package start.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import start.model.HAttr;
import start.service.IHAttrService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class HAttrCtrl {
	@Resource
	private IHAttrService service;
	
	@RequestMapping("/hattr/query")
	private Map<String,Object> query(int page,int rows){
			PageHelper.startPage(page,rows);
			List<HAttr> list=this.service.findAll();
			long  total=((Page<HAttr>)list).getTotal();
			Map<String,Object> map=new HashMap<String,Object>();
			map.put("total", total);
			map.put("rows", list);
			return map;
	}
	
	@RequestMapping("/hattr/save")
	public boolean save(HAttr bean) {
		try {
			this.service.save(bean);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
		
	}
	@RequestMapping("/hattr/remove/{id}")
	public boolean remove(@PathVariable("id") int id) {
			try {
				this.service.remove(id);
				return true;
			} catch (Exception e) {
				e.printStackTrace();
				return false;
			}
		
		
		
	}
	
	
}
